import { defineConfig, loadEnv } from 'vite'
import { visualizer } from "rollup-plugin-visualizer"
import vue from '@vitejs/plugin-vue'
import path from 'path'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd())
  return {
    plugins: [
      vue(),
      visualizer({
        //依赖分析插件
        open: false,
        filename: "dependencyAnalysis.html", //分析图生成的文件名
        gzipSize: true, // 收集 gzip 大小并将其显示
        brotliSize: true, // 收集 brotli 大小并将其显示
      })],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src')
      }
    },
    server: {
      host: '0.0.0.0', // 允许外部访问
      port: 81, // 端口号
      open: true, // 自动打开浏览器
      cors: true, // 启用跨域资源共享
      proxy: {
        [env.VITE_BASE_API]: {
          target: env.VITE_PROXY_TARGET,
          changeOrigin: true,
          rewrite: (path) => path.replace(env.VITE_APP_BASE_API, ''),
        },
        [env.VITE_ST_APP_BASE_API]: {
          target: env.VITE_PROXY_TARGET,
          changeOrigin: true,
          rewrite: (path) => path.replace(env.VITE_ST_APP_BASE_API, ''),
        },
      }
    }
  }
})


